package com.zx.controller;


import com.zx.bean.Manager;
import com.zx.bean.User;
import com.zx.dto.AjaxJson;
import com.zx.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    private UserService userService;

    //定义接口
    @PostMapping("/addUser")
    public String addUser(User user){
        return "add";
    }

    //定义一个删除接口
    @PostMapping("/delUser")
    public String delUser(int id){
        userService.delUser(id);
        return "del";
    }

    //定义一个修改的接口
    @PostMapping("/updateUser")
    public String updateFirm(int id){
        userService.updateUser(id);
        return "updateFirm";
    }

    //定义一个查询单个的接口
    @PostMapping("/findOneUser")
    @ResponseBody
    public AjaxJson findOneUser(int id){
        AjaxJson ajaxJson = new AjaxJson();
        User user = userService.findOneUser(id);
        ajaxJson.put("user",user);
        return ajaxJson;
    }

    //定义一个查询全部的接口
    @PostMapping("/findAllUser")
    @ResponseBody
    public AjaxJson findAllUser(){
        AjaxJson ajaxJson = new AjaxJson();
        userService.findAllUser();
        return ajaxJson;
    }
/*
    //管理员登录
    @PostMapping("/login")
    @ResponseBody
    public String Login(String email,String password){
        Manager manager = new Manager();
        if (manager.equals(email)&&manager.password.equals(password)){
            return "ManggerMian";
        }else{
            System.out.println("账号密码错误，请检查以后重新登陆");
        }
       return "登陆";
    }*/
}
